package android.se1;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ThirdActivity extends Activity implements OnClickListener {

	private Button postads;
	private Button signout;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home);
		postads = (Button) findViewById(R.id.postads);
		signout = (Button) findViewById(R.id.signout);
		postads.setOnClickListener(this);
		signout.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.postads:
			showRadioButtonDialog();
			break;
		case R.id.signout:
			SharedPreferences sharedPref = PreferenceManager
					.getDefaultSharedPreferences(getApplicationContext());
			SharedPreferences.Editor editor = sharedPref.edit();
			editor.remove("email");
			editor.commit();
			Intent mainScreen = new Intent(getApplicationContext(),
					MavBulletinActivity.class);
			startActivity(mainScreen);
			break;
		}
	}

	/*
	 * private void showSignOut() { signout.setOnClickListener(new
	 * View.OnClickListener() {
	 * 
	 * public void onClick(View arg0) { // Starting a new Intent
	 * SharedPreferences settings =
	 * PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
	 * SharedPreferences.Editor editor = settings.edit();
	 * editor.remove("email"); editor.commit(); Intent nextScreen = new
	 * Intent(getApplicationContext(), MavBulletinActivity.class);
	 * startActivity(nextScreen);
	 * 
	 * } }); }
	 */
	private void showRadioButtonDialog() {
		AlertDialog.Builder dialog = new AlertDialog.Builder(this);
		final String[] types = { "Books", "Housing", "Automobiles", "Furniture" };
		dialog.setTitle("Select the type");
		dialog.setSingleChoiceItems(types, -1,
				new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int select) {
						// Toast.makeText(getApplicationContext(), types[which],
						// Toast.LENGTH_SHORT).show();
						if (types[select] == "Books") {
							Intent nextScreen = new Intent(
									getApplicationContext(),
									BooksActivity.class);
							startActivity(nextScreen);
						} else if (types[select] == "Housing") {
							Intent nextScreen = new Intent(
									getApplicationContext(),
									HousingActivity.class);
							startActivity(nextScreen);
						} else if (types[select] == "Automobiles") {
							Intent nextScreen = new Intent(
									getApplicationContext(), AutoActivity.class);
							startActivity(nextScreen);
						} else if (types[select] == "Furniture") {
							Intent nextScreen = new Intent(
									getApplicationContext(),
									FurnitureActivity.class);
							startActivity(nextScreen);
						}
					}

				});

		AlertDialog alertDialog = dialog.create();
		alertDialog.show();
	}

}